function declaration
All functions that are defined and/or referenced in a program must be declared in the
prolog of that program in one of the following declaration statements:
DECLARE FUNCTION [typename] FuncName ([arglist])
INTERNAL FUNCTION [typename] FuncName ([arglist])
EXTERNAL FUNCTION [typename] FuncName ([arglist])
DECLARE FUNCTION declares functions that will be defined in the current program, and makes them visible to other programs.
INTERNAL FUNCTION declares functions that are defined in the current program, and only visible from this program.
EXTERNAL FUNCTION declares functions that are defined in another program, and must be visible from this program.
Function declarations determine the number and data type of arguments expected by functions, and the data type of the return value. When functions are called, the compiler examines the declaration information to:
Verify that the correct number of arguments have been passed to the function.
Convert each argument to the data type expected by the function before calling the
function.
Convert each argument passed by reference back to original data type after the
function returns.
Know the data type of the value returned by the function so it can be used properly
in an expression or assignment.
argument checking
In functions that take no arguments, a right parenthesis must follow the left parenthesis,
as in Func() or Func (). Otherwise a comma separated list of parameters is placed
between the parentheses. The number of arguments the function will accept, and the
data type of each is determined by the parameter list. The data type of each
parameter can be specified in one of the following ways:
typename --- Func (XLONG, STRING, GIANT, ANY)
typename followed by symbol --- Func (XLONG x, DOUBLE ddd)
symbol with a type-suffix --- Func (rip!, tear#, shred$)
any of these followed by [] --- Func (XLONG[], ANY a[], n$[])
... as final parameter --- Func (a$, ...)
ANY
Arguments can be declared as type ANY, as shown in the preceding examples. This
permits any type of variable or array to be passed in this argument position. When
arrays of different types are passed this way, the called function must check the type of
its corresponding array argument with the TYPE() intrinsic, and attach it to an
appropriate type array, before accessing its elements.
. . .
The ... parameter exists to make it possible to declare and call C functions that have a
corresponding ... parameter. ... must be the final entry in the parameter
list. ... tells the compiler to accept zero or more additional arguments of any data
type. This capability exists in C for implementing functions like printf(), where
the number of arguments and their types will vary. Native functions cannot be
declared with a ... parameter, only CFUNCTIONs.